package edu.gatech.oad.user;

import static org.junit.Assert.*;

import org.junit.Test;



/**
 * Handler that controls and implements the logging in/logging out 
 * @author Joey Slater
 * @version 1.00
 */
public class LoginController{
	
	private static final int MAXLOGINTIMES = 3;
	
	/**
	 * Class for logging the user into the system
	 * @param username the username associated with the user 
	 * @param password the password to be checked 
	 * @return the user to be logged into the system
	 */
	public User login(String username, String password){
		final User user =  //User grabber
		AccountsController.sharedController().getUserForUsername(username); 
		if(user != null){  //make sure there is a user 
			if(!user.isSuspended()){
				if(user.isPassword(password)){ //check user's password
					return user;
				}
				else{
					user.incrementLoginCount();
					if(user.getLoginCount() == MAXLOGINTIMES){
						user.setSuspended(true); //The user can no longer sign in
					}
				}
			}
		}
		return null; //no information will be shared
	}
	
	/**
	 * Method forcing the user out of the program
	 * @return the user to be null
	 */
	public User logout(){
		return null; //no information will be shared
	}
	

}
